#include <sys/types.h>
#include <sys/sysctl.h>
#include <errno.h>
#include <stdio.h>

int main( int argc, char* argv[] )
{
    int mib[4];
    mib[0] = CTL_KERN;
    mib[1] = KERN_PROC;
    mib[2] = KERN_PROC_PATHNAME;
    mib[3] = -1;
    char buf[1024];
    size_t cb = sizeof(buf);
    int ret = sysctl(mib, 4, buf, &cb, NULL, 0);

    if ( 0 == ret )
    {
        printf( "path:%s\n", buf );
    }
    else
    {
        int en = errno;
        perror( "sysctl call failed" );
        //printf( "sysctl call failed : errno=%d %s\n", en, strerror(en) );
        printf( "sysctl call failed : errno=%d \n", en );
    }

    return 0;
}


